package com.qfedu.controller;

import com.qfedu.common.JsonResult;
import com.qfedu.entity.Admin;
import com.qfedu.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

/**
 * @author:huayuzhuo
 * @email:2798866329@qq.com
 * @desc: 登录控制台
 * @datatime: 2022/10/30 12:20
 */
@Controller
public class AdminController {
    @Autowired
    private AdminService adminService;

    @RequestMapping("/login.do")
    @ResponseBody
    public JsonResult adminLogin(String username, String password, HttpSession session) {
        //参数值会根据前端页面的name来对应拿取
        Admin admin = adminService.adminLogin(username, password);
        session.setAttribute("adminLogin", admin);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode(1);
        jsonResult.setInfo("登录成功");
        return jsonResult;
    }
}
